package cn.com.haopy.yue.ai.admin.web;

import cn.com.haopy.yue.ai.admin.annotation.RequiresPermissionsDesc;
import cn.com.haopy.yue.ai.core.utils.ResponseUtil;
import cn.com.haopy.yue.ai.core.validator.Order;
import cn.com.haopy.yue.ai.core.validator.Sort;
import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapers;
import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapersIllness;
import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapersIndex;
import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskPapersOptions;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersIllnessService;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersIndexService;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersOptionsService;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskPapersService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/4/1 10:39
 */
@RestController
@RequestMapping("/admin/risk/papers")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "问卷相关")
public class AdminAiRiskPapersController {
    @Autowired
    private AIRiskPapersService papersService;

    @Autowired
    private AIRiskPapersIllnessService papersIllness;

    @Autowired
    private AIRiskPapersIndexService indexService;

    @Autowired
    private AIRiskPapersOptionsService optionsService;

    @RequiresPermissions("admin:risk:papers:list")
    @RequiresPermissionsDesc(menu = {"信息维护", "问卷管理"}, button = "列表查询")
    @GetMapping("/list")
    @ApiOperation("列表")
    public Object list(@RequestParam(required = false) @ApiParam("姓名") String name,
                       @RequestParam(required = false) @ApiParam("体检编号") String checkNo,
                       @RequestParam(required = false) @ApiParam("手机号") String mobile,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "create_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        Page<AIRiskPapers> riskPapersList = papersService.querySelective(name, checkNo, mobile, page, limit, sort, order);
        return ResponseUtil.okPage(riskPapersList);
    }

    @RequiresPermissions("admin:risk:papers:detail")
    @RequiresPermissionsDesc(menu = {"信息维护", "问卷管理"}, button = "详情")
    @GetMapping("/detail")
    @ApiOperation("详情")
    public Object detail(@RequestParam Integer id) {
        AIRiskPapers riskPapersList = papersService.getById(id);
        List<AIRiskPapersIllness> illnessList = papersIllness.getByPapersId(id);
        //指标
        List<AIRiskPapersIndex> indexList = indexService.getIndexByPapersIdNotAge(id);
        List<AIRiskPapersOptions> optionsList = optionsService.getByPapersId(id);
        Map<String, Object> data = new HashMap<>();
        data.put("riskPapersList", riskPapersList);
        data.put("illnessList", illnessList);
        data.put("indexList", indexList);
        data.put("optionsList", optionsList);
        return ResponseUtil.ok(data);
    }
}
